<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>学校固定资产管理系统 </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a>首页</a>
            <a>资产信息</a>
            <a>
                <cite>资产列表</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <div class="layui-collapse" lay-filter="test">
                            <div class="layui-colla-item">
                                <h2 class="layui-colla-title">条件筛选
                                    <i class="layui-icon layui-colla-icon"></i>
                                </h2>
                                <div class="layui-colla-content">
                                    <form class="layui-form">
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label">资产编号</label>
                                                <div class="layui-input-inline" style="width: 190px;">
                                                    <input type="text" name="AssetsNum" id="assetsNum" placeholder="资产编号" autocomplete="off" class="layui-input">
                                                </div>
                                                <label class="layui-form-label">资产名称</label>
                                                <div class="layui-input-inline" style="width: 190px;">
                                                    <input type="text" name="AssetsName" id="assetsName" placeholder="资产名称" autocomplete="off" class="layui-input">
                                                </div>
                                                <label class="layui-form-label">资产价值</label>
                                                <div class="layui-input-inline" style="width: 80px;">
                                                    <input type="text" name="DecimalMin" placeholder="￥" autocomplete="off" class="layui-input">
                                                </div>
                                                <div class="layui-form-mid">-</div>
                                                <div class="layui-input-inline" style="width: 80px;">
                                                    <input type="text" name="DecimalMax" placeholder="￥" autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                        </div>

                                        <div class="layui-form-item">
                                            <label for="L_type" class="layui-form-label">资产类型</label>
                                            <div class="layui-input-inline" style="width: 190px;">
                                                <select id="L_type" name="TypeId" lay-filter="type">
                                                    <option value="">请选择</option>
                                                </select>
                                            </div>
                                            <label for="L_source" class="layui-form-label">资产来源</label>
                                            <div class="layui-input-inline" style="width: 190px;">
                                                <select id="L_source" name="SourceId" lay-filter="source">
                                                    <option value="">请选择</option>
                                                </select>
                                            </div>
                                            <label for="L_status" class="layui-form-label">资产状况</label>
                                            <div class="layui-input-inline" style="width: 190px;">
                                                <select id="L_status" name="StatusId" lay-filter="status">
                                                    <option value="">请选择</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <label for="" class="layui-form-label">负责人</label>
                                            <div class="layui-input-inline" style="width: 90px;">
                                                <select id="L_principalDepartment" name="PrincipalDepartmentId" lay-filter="principalDepartment">
                                                    <option value="">请选择</option>
                                                </select>
                                            </div>
                                            <div class="layui-input-inline" style="width: 90px;">
                                                <select id="L_principalUser" name="PrincipalUserId" lay-filter="principalUser">
                                                    <option value="">请选择</option>
                                                </select>
                                            </div>
                                            <label for="" class="layui-form-label">入库人</label>
                                            <div class="layui-input-inline" style="width: 90px;">
                                                <select id="L_storageDepartment" name="StorageDepartmentId" lay-filter="storageDepartment">
                                                    <option value="">请选择</option>
                                                </select>
                                            </div>
                                            <div class="layui-input-inline" style="width: 90px;">
                                                <select id="L_storageUser" name="StorageUserId" lay-filter="storageUser">
                                                    <option value="">请选择</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="layui-inline layui-show-xs-block">
                                            <button class="layui-btn" id="searchBtn" lay-submit="" lay-filter="search">
                                                <i class="layui-icon">&#xe615;查询</i>
                                            </button>
                                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body ">
                        <table id="assets"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    //初始状态
    var status = ["正常", "闲置", "内部转移","故障","遗失","资产处置"]
    layui.use('table', function () {
        var table = layui.table;
        //表格实例化
        table.render({
            elem: '#assets'
            , height: 500
            , headers: { 'token': sessionStorage.getItem("token") }
            , url: sessionStorage.getItem("api") + 'assets/list'
            , where: { StatusStr: status }
            , page: true
            , request: {
                pageName: 'PageIndex'
                , limitName: 'PageSize'
            }
            , parseData: function (res) {
                return {
                    "code": res.Data.Code,
                    "msg": res.Data.Msg,
                    "count": res.Data.Count,
                    "data": res.Data.Data
                };
            }
            , cols: [
                [
                    { type: 'numbers', title: '序号', width: 80 }
                    , { field: 'AssetsNum', title: '编号' ,width: 100 }
                    , { field: 'AssetsName', title: '名称' ,width: 140 }
                    , { field: 'AssetsDescribe', title: '描述' }
                    , { field: 'DecimalStr', title: '价值', width: 150 }
                    , { field: 'Type', title: '类型' , width: 80}
                    , { field: 'AgeLimitStr', title: '建议使用年限' , width: 80}
                    , { field: 'Source', title: '来源', width: 80 }
                    , { field: 'Status', title: '状况' , width: 80}
                    , {
                        title: '负责人',width: 150 ,
                        templet: function (d) {
                            return d.PrincipalDepartment + " " + d.PrincipalUser
                        }
                    }
                    , {
                        title: '入库人',width: 150 ,
                        templet: function (d) {
                            return d.StorageDepartment + " " + d.StorageUser
                        }
                    }
                ]
            ]
        });



    });
</script>

<script>
    layui.use(['form', 'layer', 'jquery'],
        function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            layui.use('table', function () {
                var table = layui.table;
                //监听提交
                form.on('submit(search)',
                    function (data) {
                        table.reload('assets', {
                            where: data.field
                            , page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                        return false;
                    });
            })

            //获取类型
            $.ajax({
                type: "GET",
                headers: { "token": sessionStorage.getItem("token") },
                url: sessionStorage.getItem("api") + "types/infos",
                dataType: "Json",
                success: function (res) {
                    if (res.Code == 200) {
                        var html = '';
                        for (var i = 0; i < res.Data.length; i++) {
                            var item = res.Data[i];
                            html += '<option value="' + item.Id + '">' + item.TypeName + '</option>'
                        }
                        $("#L_type").append(html);
                        form.render();
                    } else {
                        layer.msg(res.ErrorMessage);    
                    }
                }
            })

            //获取来源
            $.ajax({
                type: "GET",
                headers: { "token": sessionStorage.getItem("token") },
                url: sessionStorage.getItem("api") + "source/infos",
                dataType: "Json",
                success: function (res) {
                    if (res.Code == 200) {
                        var html = '';
                        for (var i = 0; i < res.Data.length; i++) {
                            var item = res.Data[i];
                            html += '<option value="' + item.Id + '">' + item.SourceName + '</option>'
                        }
                        $("#L_source").append(html);
                        form.render();
                    } else {
                        layer.msg(res.ErrorMessage);
                    }
                }
            })

            //获取状况
            $.ajax({
                type: "GET",
                headers: { "token": sessionStorage.getItem("token") },
                url: sessionStorage.getItem("api") + "status/infos",
                dataType: "Json",
                success: function (res) {
                    if (res.Code == 200) {
                        var html = '';
                        for (var i = 0; i < res.Data.length; i++) {
                            var item = res.Data[i];
                            html += '<option value="' + item.Id + '">' + item.StatusName + '</option>'
                        }
                        $("#L_status").append(html);
                        form.render();
                    } else {
                        layer.msg(res.ErrorMessage);
                    }
                }
            })

            //获取部门
            $.ajax({
                type: "GET",
                headers: { "token": sessionStorage.getItem("token") },
                url: sessionStorage.getItem("api") + "department/infos",
                dataType: "Json",
                success: function (res) {
                    if (res.Code == 200) {
                        var html = '';
                        for (var i = 0; i < res.Data.Count; i++) {
                                var item = res.Data.Data[i];
                            html += '<option value="' + item.Id + '">' + item.DepartmentName + '</option>'
                        }
                        $("#L_principalDepartment").append(html);
                        $("#L_storageDepartment").append(html);
                        form.render();
                    } else {
                        layer.msg(res.ErrorMessage);
                    }
                }
            })

            //加载部门的用户
            form.on('select(principalDepartment)', function (data) {
                $.ajax({
                    type: "GET",
                    headers: { "token": sessionStorage.getItem("token") },
                    url: sessionStorage.getItem("api") + 'department/' + data.value + '/list',
                    dataType: "Json",
                    success: function (res) {
                        if (res.Code == 200) {
                            var html = '<option value="">请选择</option>';
                            for (var i = 0; i < res.Data.length; i++) {
                                var item = res.Data[i];
                                html += '<option value="' + item.Id + '">' + item.UserName + '</option>'
                            }
                            $("#L_principalUser").html(html);
                            form.render();
                        } else {
                            layer.msg(res.ErrorMessage);
                        }
                    }
                })
            });
            form.on('select(storageDepartment)', function (data) {
                $.ajax({
                    type: "GET",
                    headers: { "token": sessionStorage.getItem("token") },
                    url: sessionStorage.getItem("api") + 'department/' + data.value + '/list',
                    dataType: "Json",
                    success: function (res) {
                        if (res.Code == 200) {
                            var html = '<option value="">请选择</option>';
                            for (var i = 0; i < res.Data.length; i++) {
                                var item = res.Data[i];
                                html += '<option value="' + item.Id + '">' + item.UserName + '</option>'
                            }
                            $("#L_storageUser").html(html);
                            form.render();
                        } else {
                            layer.msg(res.ErrorMessage);
                        }
                    }
                })
            });

        })  
</script>

</html>